/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.nbg.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.nbg.entity.NbgBaseData;
import com.zcm.modules.nbg.service.NbgBaseDataService;

/**
 * baseDataController
 * @author www
 * @version 2018-10-02
 */
@Controller
@RequestMapping(value = "${adminPath}/nbg/nbgBaseData")
public class NbgBaseDataController extends BaseController {

	@Autowired
	private NbgBaseDataService nbgBaseDataService;
	
	@ModelAttribute
	public NbgBaseData get(@RequestParam(required=false) String id) {
		NbgBaseData entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nbgBaseDataService.get(id);
		}
		if (entity == null){
			entity = new NbgBaseData();
		}
		return entity;
	}
	
	@RequiresPermissions("nbg:nbgBaseData:view")
	@RequestMapping(value = {"list", ""})
	public String list(NbgBaseData nbgBaseData, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<NbgBaseData> page = nbgBaseDataService.findPage(new Page<NbgBaseData>(request, response), nbgBaseData); 
		model.addAttribute("page", page);
		return "modules/nbg/nbgBaseDataList";
	}

	@RequiresPermissions("nbg:nbgBaseData:view")
	@RequestMapping(value = "form")
	public String form(NbgBaseData nbgBaseData, Model model) {
		model.addAttribute("nbgBaseData", nbgBaseData);
		return "modules/nbg/nbgBaseDataForm";
	}

	@RequiresPermissions("nbg:nbgBaseData:edit")
	@RequestMapping(value = "save")
	public String save(NbgBaseData nbgBaseData, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, nbgBaseData)){
			return form(nbgBaseData, model);
		}
		nbgBaseDataService.save(nbgBaseData);
		addMessage(redirectAttributes, "保存baseData成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgBaseData/?repage";
	}
	
	@RequiresPermissions("nbg:nbgBaseData:edit")
	@RequestMapping(value = "delete")
	public String delete(NbgBaseData nbgBaseData, RedirectAttributes redirectAttributes) {
		nbgBaseDataService.delete(nbgBaseData);
		addMessage(redirectAttributes, "删除baseData成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgBaseData/?repage";
	}

}